﻿using Models;
using Models.RModels;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace RedisHelper.User
{
    public class UserInfo
    {
        /// <summary>
        /// 插入用户数据
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="r_UserInfo"></param>
        /// <returns></returns>
        public bool InsertUserInfo(int uid, R_UserInfo r_UserInfo)
        {
            using (RedisHelper rh = new RedisHelper())
            {
                try
                {
                    rh.GetDatabase(2).HashSet(StaticConfigRidesName.UserInfo_Hash(), uid, JsonConvert.SerializeObject(r_UserInfo));
                    return true;
                }
                catch (Exception ex)
                {
                    return false;
                }
                
            }
        }

        /// <summary>
        /// 获取用户信息
        /// </summary>
        /// <param name="uid">用户编号</param>
        /// <returns>如何没有查询到则返回null</returns>
        public R_UserInfo GetUserInfo(int uid)
        {
            using (RedisHelper rh = new RedisHelper())
            {
                var data = rh.GetDatabase(2).HashGet(StaticConfigRidesName.UserInfo_Hash(), uid);
                if (data.IsNull)
                    return null;
                else
                    return JsonConvert.DeserializeObject<R_UserInfo>(data);
            }
        }
    }
}
